import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: "/login",
    component:()=>import("../pages/login/login.vue"),
    meta: {
      title: "手机登录",
      back: true
    }
  },
  {
    path: "/register",
    component:()=>import("../pages/register/register.vue"),
    meta: {
      title: "注册",
      back: true
    }
  },
  {
    path: "/index",
    component: () => import("../pages/index/index.vue"),
    children: [
      {
        path: "home",
        component: () => import("../pages/home/home.vue"),
        meta: { title: "首页" }
      },
      { 
        path: "cate", 
        component: () => import("../pages/cate/cate.vue"), 
        meta: { title: "分类" } 
      },
      { 
        path: "shop", 
        component: () => import("../pages/shop/shop.vue"), 
        meta: { title: "购物车" } 
      },
      { 
        path: "mine", 
        component: () => import("../pages/mine/mine.vue"), 
        meta: { title: "个人中心" } 
      },
    ]
  },
  {
    path: "/list",
    name: "列表",
    component: () => import("../pages/list/list.vue"),
    meta: {
      title: "商品列表",
      back: true
    }
  },
  {
    path: "/detail/:id",
    name: "详情",
    component: () => import("../pages/detail/detail.vue"),
    meta: {
      title: "商品详情",
      back: true
    }
  },
  {
    path: "/search",
    alias: "/s",
    name: "搜索",
    component: () => import("../pages/search/search.vue"),
    meta: {
      title: "搜索",
      back: true
    }
  },
  {
    path: "/order",
    component:()=>import("../pages/order/order.vue"),
    meta: {
      title: "确认订单",
      back: true
    }
  },
  {
    path: "/pay",
    component:()=>import("../pages/pay/pay.vue"),
    meta: {
      title: "支付订单",
      back: true
    }
  },
  {
    path: "/a-list",
    component:()=>import("../pages/a-list/list.vue"),
    meta: {
      title: "地址管理",
      back: true
    }
  },
  {
    path: "/a-add",
    component:()=>import("../pages/a-add/add.vue"),
    meta: {
      title: "编辑地址",
      back: true
    }
  },
  {
    path:"*",
    redirect:"/login"
  },
]

const router = new VueRouter({
  mode:"history",
  routes,
  scrollBehavior(to, from, savePosition) {
    return savePosition ? savePosition : { x: 0, y: 0 }
  }
})

export default router
